package test_model_base;


import java.sql.Date;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.servlet.model.base.Area;
import com.servlet.model.base.Profile;
import com.servlet.model.base.Status;

public class ProfileTest extends TestCase {
	private Profile p;
	private Date birth;
	private Status s;
	private Area a;
	
	@Before
	public void setUp() throws Exception {
		super.setUp();
		birth = Date.valueOf("1988-01-26");
		s = new Status();
		a = new Area(91400, "france", "orsay");
		p = new Profile("jialin.liu@u-psud.fr", "jialin", "liu", birth, s, "liu.jpg", a, 5, 5);
	}

	@After
	public void tearDown() throws Exception {
		birth = null;
		s = null;
		a = null;
		p = null;
	}

	@Test
	public void testProfile() {
		p = new Profile();
		Assert.assertNull(p.getStatus());
		Assert.assertNull(p.getPhoto());
		Assert.assertEquals(Area.areaVide, p.getWorldArea());
		Assert.assertEquals(12, p.getNb_contacts_par_page());
		Assert.assertEquals(10, p.getNb_news_par_page());
		Assert.assertEquals(false, p.getIs_modified_status());
		Assert.assertEquals(false, p.getIs_modified_photo());
		Assert.assertEquals(false, p.getIs_modified_world_area());
		Assert.assertEquals(false, p.getIs_modified_nb_contacts_par_page());
		Assert.assertEquals(false, p.getIs_modified_nb_news_par_page());
	}

	@Test
	public void testProfileStringStringStringDate() {
		Date d = Date.valueOf("1988-11-04");
		p = new Profile("jingjing.li@u-psud.fr", "jingjing", "li", d);
		
		Assert.assertEquals("jingjing.li@u-psud.fr",p.getEmail());
		Assert.assertEquals("jingjing", p.getFirst_name());
		Assert.assertEquals("li", p.getLast_name());
		Assert.assertEquals(d, p.getBirth_date());
		Assert.assertEquals(false, p.getIs_modified_birth_date());
		Assert.assertEquals(false, p.getIs_modified_first_name());
		Assert.assertEquals(false, p.getIs_modified_last_name());
		
		Assert.assertNull(p.getStatus());
		Assert.assertNull(p.getPhoto());
		Assert.assertEquals(Area.areaVide, p.getWorldArea());
		Assert.assertEquals(10, p.getNb_contacts_par_page());
		Assert.assertEquals(10, p.getNb_news_par_page());
		Assert.assertEquals(false, p.getIs_modified_status());
		Assert.assertEquals(false, p.getIs_modified_photo());
		Assert.assertEquals(false, p.getIs_modified_world_area());
		Assert.assertEquals(false, p.getIs_modified_nb_contacts_par_page());
		Assert.assertEquals(false, p.getIs_modified_nb_news_par_page());
	}

	@Test
	public void testProfileStringStringStringDateStatusStringInt() {
		Date d = Date.valueOf("1988-11-04");
		a = new Area(33033, "chine", "wuhan");
		p = new Profile("jingjing.li@u-psud.fr", "jingjing", "li", d, s, "li.jpg", a, 3, 3);
		
		Assert.assertEquals("jingjing.li@u-psud.fr",p.getEmail());
		Assert.assertEquals("jingjing", p.getFirst_name());
		Assert.assertEquals("li", p.getLast_name());
		Assert.assertEquals(d, p.getBirth_date());
		Assert.assertEquals(false, p.getIs_modified_birth_date());
		Assert.assertEquals(false, p.getIs_modified_first_name());
		Assert.assertEquals(false, p.getIs_modified_last_name());
		
		Assert.assertEquals(s, p.getStatus());
		Assert.assertEquals("li.jpg", p.getPhoto());
		Assert.assertEquals(a, p.getWorldArea());
		Assert.assertEquals(3, p.getNb_contacts_par_page());
		Assert.assertEquals(3, p.getNb_news_par_page());
		Assert.assertEquals(false, p.getIs_modified_status());
		Assert.assertEquals(false, p.getIs_modified_photo());
		Assert.assertEquals(false, p.getIs_modified_world_area());
		Assert.assertEquals(false, p.getIs_modified_nb_contacts_par_page());
		Assert.assertEquals(false, p.getIs_modified_nb_news_par_page());
	}

	@Test
	public void testGetStatus() {
		Assert.assertEquals(s, p.getStatus());
	}

	@Test
	public void testGetPhoto() {
		Assert.assertEquals("liu.jpg", p.getPhoto());
	}

	@Test
	public void testGetWorld_area() {
		Assert.assertEquals(a, p.getWorldArea());
	}

	@Test
	public void testGetIs_modified_status() {
		Assert.assertEquals(false, p.getIs_modified_status());
	}

	@Test
	public void testGetIs_modified_photo() {
		Assert.assertEquals(false, p.getIs_modified_photo());
	}

	@Test
	public void testGetIs_modified_world_area() {
		Assert.assertEquals(false, p.getIs_modified_world_area());
	}

	@Test
	public void testSetIs_modified_status() {
		p.setIs_modified_status(true);
		Assert.assertEquals(true, p.getIs_modified_status());
	}

	@Test
	public void testSetIs_modified_photo() {
		p.setIs_modified_photo(true);
		Assert.assertEquals(true, p.getIs_modified_photo());
	}

	@Test
	public void testSetIs_modified_world_area() {
		p.setIs_modified_world_area(true);
		Assert.assertEquals(true, p.getIs_modified_world_area());
	}

	@Test
	public void testSetPhoto() {
		p.setPhoto("li.jpg");
		Assert.assertEquals("li.jpg", p.getPhoto());
	}

	@Test
	public void testSetStatus() {
		s = new Status("Recherche un ou plusieurs employs");
		p.setStatus(s);
		Assert.assertEquals(s, p.getStatus());
	}

	@Test
	public void testSetWorld_area() {
		a = new Area(33033, "chine", "wuhan");
		p.setWorld_area(a);
		Assert.assertEquals(("33033chinewuhan").hashCode(), p.getWorldArea().getHCode());
	}
}
